package mediator;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Scanner;

/**
 * Class used for reading configuration file
 * @author Echipa Racheta
 *
 */
public class ConfigReader {

	public String loggedUsr;
	public String username;
	public String pass;
	public String type;
	int nr;
	public ArrayList<String> services;
	
	public ConfigReader(String usr) {
		services = new ArrayList<String>();
		loggedUsr = usr;
	}
	
	public void readConfigFile(){ 
		
		String configFileName = "configFile_" + loggedUsr;
		File f = new File(configFileName);
		
		System.out.println(configFileName);
		if (!f.exists()) {
			username = "-1";
			pass = "";
			type = "";
			return;
		}
		
		Scanner s = null;
		try {
			s = new Scanner(f);
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		username = s.nextLine();
		pass = s.nextLine();
		type = s.nextLine();
		nr = Integer.parseInt(s.nextLine());

		for (int i = 0 ; i< nr ; i++ ) {
			services.add(s.nextLine());
		}
	}
}
